package hu;

import java.util.*;

public class hu46 {
    static class node{
        int val;
        node next;

        public node(int val, node next) {
            this.val = val;
            this.next = next;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int head = Integer.parseInt(str[1]);
        node h = new node(head, null);
        for (int i = 2; i < str.length - 1; i = i + 2) {
            int a = Integer.parseInt(str[i]);
            int b = Integer.parseInt(str[i + 1]);
            node p = h;
            while(p != null){
                if(p.val == b){
                    node n1 = new node(a, p.next);
                    p.next = n1;
                }
                p = p.next;
            }
        }
        int de = Integer.parseInt(str[str.length - 1]);
        node p = h;
        node c = h.next;
        if(de == h.val){
            h = h.next;
        }
        else{
            while(c != null){
                if(c.val == de){
                    p.next = c.next;
                    break;
                }
                p = p.next;
                c = c.next;
            }
        }
        while(h != null){
            System.out.print(h.val + " ");
            h = h.next;
        }

    }
}
